/*
 * Copyright (c) 2011-2022, baomidou (jobob@qq.com).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.baomidou.mybatisplus.advance.query;


import com.baomidou.mybatisplus.advance.query.enums.DirectionEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.io.Serializable;

/**
 * 排序字段
 * @author wanglei
 * @since 2022-03-14
 */
@Data
@ApiModel(
        description = "排序字段"
)
@Schema(title = "排序字段")
public class FieldSort implements Serializable {
    private static final long serialVersionUID = -1712830705595375365L;
    @ApiModelProperty(
            name = "property",
            notes = "排序字段名"
    )
    @Schema(description = "排序字段名" , name = "property",title = "排序字段名")
    private String property;
    @ApiModelProperty(
            name = "direction",
            notes = "排序方向",
            example = "ASC"
    )
    @Schema(description = "排序方向 升序ASC 降序DESC " , example = "ASC",name = "direction",title = "排序方向")
    private DirectionEnum direction;

    public FieldSort() {
        this.direction = DirectionEnum.ASC;
    }

    public FieldSort(String property) {
        this(property, DirectionEnum.ASC);
    }

    public FieldSort(String property, DirectionEnum direction) {
        this.direction = direction;
        this.property = property;
    }

    public static FieldSort create(String property, String direction) {
        return new FieldSort(property, DirectionEnum.fromString(direction));
    }


}
